package cn.hchaojie.javase.day03;

import org.junit.Test;

public class Ex1 {
	@Test
	public void test1() {
		int[] array1 = {2,8,10,12,33};
		int[] array2 = {2,4,3,9,10};
		
		System.out.println(isSorted(array1));
		System.out.println(isSorted(array2));
	}
	
	// 数组是否已排序
	
	/*
	 * 方法定义如下：public static boolean isSorted(int[] numbers);
		传入数组{2,8,10,12,33}时，返回true
		传入数组{2,4,3,9,10}时，返回false
	 */
	public static boolean isSorted(int[] numbers) {
		boolean sorted = true;
		
		for (int i = 0; i < numbers.length - 1; i++) {
			if (numbers[i] > numbers[i + 1]) {
				sorted = false;
				break;
			}
		}
		
		return sorted;
	}
}
